n = int(input())
nums = list(map(int, input().split()))
arr = [bin(num) for num in nums]
ans = 0
for bit in range(21):
    cnt = [0, 0]
    for i, num in enumerate(nums):
        if num & (1 << bit):
            ans += (1 << bit) * (cnt[0] + 1)
            cnt[1], cnt[0] = cnt[0], cnt[1]
            cnt[1] += 1
        else:
            cnt[0] += 1
            ans += (1 << bit) * cnt[1]
print(ans)
